import os
#设定文件路径
jpg_path='dataset/JPEGImages/'
anno_path = 'dataset/Annotations/'
i=1
#对目录下的文件进行遍历
for file in os.listdir(jpg_path):
#判断是否是文件
    if os.path.isfile(os.path.join(jpg_path,file))==True:
#设置新文件名
        main = file.split('.')[0]
        if " " in main:
            new_main = main.replace(' ','')
            new_main_jpg = new_main + '.jpg'
            new_main_anno = new_main + '.xml'
            print(os.path.join(jpg_path,new_main_jpg))
            print(os.path.join(anno_path,new_main_anno))

#         new_name=file.replace(file,"rgb_%d.jpg"%i)
# #重命名
            os.rename(os.path.join(jpg_path,main+'.jpg'),os.path.join(jpg_path,new_main_jpg))
            os.rename(os.path.join(anno_path,main+'.xml'),os.path.join(anno_path,new_main_anno))
            i+=1
#结束
print ("End")